package com.cqut.forum.entity;

import static javax.persistence.GenerationType.IDENTITY;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

/**
 * @author yangxun
 * Module entity
 */
@Entity
@Table(name = "module", catalog = "forum")
public class Module implements java.io.Serializable {

	// Fields

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private Integer moduleId;
	private String moduleName;
	private Boolean moduleState;
	//private ModuleInformation moduleInformation;
	private Set<Level> levels = new HashSet<Level>(0);
	//private Set<ModuleInformation> moduleInformation = new HashSet<ModuleInformation>(0);
	private ModuleInformation moduleInformation;
	// Constructors

	/** default constructor */
	public Module() {
	}

	/** full constructor */
	public Module(String moduleName,/*ModuleInformation moduleInfomation, */Boolean moduleState, 
			Set<Level> levels,ModuleInformation moduleInformation) {
		this.moduleName = moduleName;
		this.moduleState = moduleState;
		//this.moduleInformation = moduleInfomation;
		this.levels = levels;
		this.moduleInformation = moduleInformation;
	}

	// Property accessors
	@Id
	@GeneratedValue(strategy = IDENTITY)
	@Column(name = "module_id", unique = true, nullable = false)
	public Integer getModuleId() {
		return this.moduleId;
	}

	public void setModuleId(Integer moduleId) {
		this.moduleId = moduleId;
	}

	@Column(name = "module_name", length = 100)
	public String getModuleName() {
		return this.moduleName;
	}

	public void setModuleName(String moduleName) {
		this.moduleName = moduleName;
	}

	@Column(name = "module_state")
	public Boolean getModuleState() {
		return this.moduleState;
	}

	public void setModuleState(Boolean moduleState) {
		this.moduleState = moduleState;
	}

	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "module")
	public Set<Level> getLevels() {
		return this.levels;
	}

	public void setLevels(Set<Level> levels) {
		this.levels = levels;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "module_information_id")
	public ModuleInformation getModuleInformation() {
		return moduleInformation;
	}

	public void setModuleInformation(ModuleInformation moduleInformation) {
		this.moduleInformation = moduleInformation;
	}


	
/*	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "module_information_id")
	public ModuleInformation getModuleInformation() {
		return this.moduleInformation;
	}

	public void setModuleInformation(ModuleInformation moduleInformation) {
		this.moduleInformation = moduleInformation;
	}*/
}